package org.autumn.structure.tree;

/**
 * 二叉平衡树
 */
public class AvlTree {

    private Node root;

    public void add(int id) {
        Node addition = new Node(id, null, null);
        if (root == null) {
            root = addition;
        } else {
        }
    }

    public int treeDepth(Node root) {
        if (root == null) {
            return 0;
        }
        int left = treeDepth(root.getLeft());
        int right = treeDepth(root.getRight());
        return left > right ? left + 1 : right + 1;

    }

    // 节点
    class Node {
        private int id;
        private Node left;
        private Node right;

        public Node() {
        }

        public Node(int id, Node left, Node right) {
            this.id = id;
            this.left = left;
            this.right = right;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public Node getLeft() {
            return left;
        }

        public void setLeft(Node left) {
            this.left = left;
        }

        public Node getRight() {
            return right;
        }

        public void setRight(Node right) {
            this.right = right;
        }

        @Override
        public String toString() {
            return "Node{" +
                    "id=" + id +
                    '}';
        }
    }
}
